package ru.st.selenium.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class LoginPage extends Page {

    @FindBy(xpath = "//input[@name='username']")
    private WebElement userNameField;

    @FindBy(xpath = "//input[@name='password']")
    private WebElement passwordField;

    @FindBy(xpath = "//input[@name='submit']")
    private WebElement logInBtn;

    public LoginPage(WebDriver webDriver) {
        super(webDriver);
    }

    public LoginPage setUserName(String user) {
        userNameField.clear();
        userNameField.sendKeys(user);
        return this;
    }

    public LoginPage setPasswordField(String pass) {
        passwordField.clear();
        passwordField.sendKeys(pass);
        return this;
    }

    public HomePage clickLogIn() {
        logInBtn.click();
        return PageFactory.initElements(getWebDriver(), HomePage.class);
    }

    public HomePage logIn(String username, String pass) {
        return setUserName(username).setPasswordField(pass).clickLogIn();
    }
}
